package com.lingshi.shopping_manager_api.security;

import cn.dev33.satoken.stp.StpInterface;
import com.lingshi.shopping_common.entity.Permission;
import com.lingshi.shopping_common.service.IAdminService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class StpInterfaceImpl implements StpInterface {
    @DubboReference
    private IAdminService adminService;

    /**
     * 获取当前登录用户所有权限，进行权限校验使用
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {

        List<Permission> permissions = adminService.findAllPermission(loginId.toString());
        List<String> urls = permissions.stream().map(Permission::getUrl).collect(Collectors.toList());
        return urls;
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
